console.log('Map测试');

let mapDada = new Map();

// 添加键值对
mapDada.set('name', 'mapName')
mapDada.set('age', 18)
mapDada.set('work', 'IT')
mapDada.set('温度', 'TEMP')

console.log(mapDada);

// 获取值
console.log(mapDada.get('name'))
console.log(mapDada.get('温度'))

// 检查键是否存在

console.log(mapDada.has('name'));

// 删除键值对
// mapDada.delete('name')

// 遍历键值对 for 循环
console.log('for 循环==========================');
for (const [k, v] of mapDada) {
    console.log(k, v);
}

for (const iterator of mapDada.keys()) {
    console.log(iterator);
}

for (const iterator of mapDada.values()) {
    console.log(iterator);
}


// forEach
console.log('forEach============================');
mapDada.forEach((k, v) => {
    console.log(k, v);
})

// 迭代器iterator
console.log('=================entries=================');
let iterators = mapDada.entries();
// console.log(iterators, 'iterator');
// 迭代器取值
// console.log(iterators.next()); 
// console.log(iterators.next());
let result = iterators.next();
while(!result.done){
    let [k, v] = result.value;
    console.log(k, v);
    result = iterators.next();
}

const mapData2 = new Map();
mapData2.set("key1", "value1");
mapData2.set("key2", "value2");

const iterator2 = mapData2.values(); // 获取值的迭代器对象

console.log(iterator2.next().value); // 输出第一个值
console.log(iterator2.next().value); // 输出第二个值



